package com.example.shopping.login.mapper;

import com.example.shopping.login.entity.*;
import org.apache.ibatis.annotations.*;


import java.util.List;

@Mapper
public interface LoginMapper {
    //查询用户where name =#{name} and password =#{password}
    @Select("select * from user where account =#{account} and password =#{password}")
    List<Login> getLogin(String account, String password);

    //轮播图
    @Select("select * from homepage")
    List<SlideShow> getSlideShow();

    //添加购物车
    @Insert("insert into cart\n" +
            "(userid," +
            "productid," +
            "goodsname," +
            "goodsprice," +
            "goodsimg)" +
            "values\n" +
            "(#{userid},#{productid},#{goodsname},#{goodsprice},#{goodsimg})")
    int CartADD(int userid,int productid,String goodsname,Double goodsprice,String goodsimg);


    //用户查询收藏
    @Select("select * from collection where userid=#{userid} and productid =#{productid}")
    List<Collection> getCollectionIdList(int userid, int productid);

    //添加收藏
    @Insert("insert into collection\n" +
            "(id,productid,userid) \n" +
            "values\n" +
            "(null,#{productid},#{userid})\n")
    int AddCollection(int id,int productid,int userid);

    //删除收藏
    @Delete("DELETE FROM collection where id=#{id}")
    int DeleCollection(int id);

    //查询购物车全部商品
    @Select("select * from cart where userid=#{userid}")
    List<Cart> getCartFind(@Param("userid")int userid);

    //修改购物车数量
    @Update("UPDATE cart set quantity = #{quantity} where userid=#{userid} and productid=#{productid}")
    int getCartUpdate(@Param("quantity")int quantity,@Param("userid")int userid,@Param("productid")int productid);




    //用户所用查询用户
    //@Select("select * from userstate")
    //Userstate getUserstate();

    //用户所用查询用户
    @Select("select * from userstate where usercloudid=#{usercloudid}")
    Userstate getUserstateusercloudid(String usercloudid);

    //添加用户
    @Insert("insert into userstate\n" +
            "(id,isshow,userid,username,userprofile,usercloudid)  \n" +
            "values\n" +
            "(null,#{isshow},#{userid},#{username},#{userprofile},#{usercloudid})\n")
    int AddUserstate(Userstate userstate);

    //修改用户id
    @Update("UPDATE userstate SET userid=#{userid} where usercloudid=#{usercloudid}")
    int UpUserstate(Userstate userstate);
}
